{include file="public/header" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
<style type="text/css">
  #des, #des input {
    width: 40px;
    text-align: center;
  }
  #id {
    width: 78px;
  }
  .bs-checkbox {
    width: 36px;
    height: 40px
  }
  .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
    margin-left: 0px;
    margin-top: 0px
  }
  #title span {
    float: right;
    margin-left: 3.333px;
  }
  .search {
    margin-bottom: 0px !important;
  }
  .asdlkjasd {
    background: #1ab394;
    color: #fff
  }
  #title {
    position: relative;
    padding-right: 50px;
  }
  #title span {
    position: absolute;
    top: 12px;
    right: 10px;
  }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
  <div class="ibox float-e-margins">
    {include file="public/tophead"}
    {include file="public/top" /}
    <div class="ibox-content">
      {include file="public/topsection"}
      <div class="row row-lg">
        <div class="col-sm-12">
          <div class="fixed-table-toolbar">
              <a class="btn btn-default btn-outline {notpresent name='status'}asdlkjasd{/notpresent}" href="{:url('index')}{present name='state'}/state/{$state}{/present}">全部</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='0'}asdlkjasd{/eq}{/present}" href="{:url('index',['status' => 0])}{present name='state'}/state/{$state}{/present}">待审核</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='1'}asdlkjasd{/eq}{/present}" href="{:url('index',['status' => 1])}{present name='state'}/state/{$state}{/present}">已通过</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='-1'}asdlkjasd{/eq}{/present}" href="{:url('index',['status' => -1])}{present name='state'}/state/{$state}{/present}">已拒绝</a>
          </div>
          <div class="fixed-table-toolbar">
              <a class="btn btn-default btn-outline {notpresent name='state'}asdlkjasd{/notpresent}" href="{:url('index')}{present name='status'}/status/{$status}{/present}">全 部</a>
              <a class="btn btn-default btn-outline {present name='state'}{eq name='state' value='0'}asdlkjasd{/eq}{/present}" href="{:url('index',['state' => 0])}{present name='status'}/status/{$status}{/present}">报名中</a>
              <a class="btn btn-default btn-outline {present name='state'}{eq name='state' value='1'}asdlkjasd{/eq}{/present}" href="{:url('index',['state' => 1])}{present name='status'}/status/{$status}{/present}">已结束</a>
              <a class="btn btn-default btn-outline {present name='state'}{eq name='state' value='-1'}asdlkjasd{/eq}{/present}" href="{:url('index',['state' => -1])}{present name='status'}/status/{$status}{/present}">已过期</a>
          </div>
          <div class="fixed-table-toolbar">
            <form  method="get" action="">
              <div class="pull-left search">
                {php}
                if(input('?param.name')){
                {/php}
                <div class="pull-right search">
                  <a class="btn btn-w-m btn-link" href="{:url('index')}">返回地址管理</a>
                </div>{php}
                }
                {/php}
                <div class="columns columns-right btn-group pull-left" >
                  <select class="form-control" name="search">
                    <option value="user_id">用户ID</option>
                    <option value="content" {present name='search'}{eq name='search' value='content'}selected{/eq}{/present}>内容</option>
                  </select>
                </div>


                <div class="pull-right search" style="display: flex;">
                  <input name="start" type="text" id="start" class="form-control layui-input" value="{present name='start'}{$start}{/present}" placeholder=" # 起始时间" autocomplete="off" style="height:34px;width:180px;margin:0 10px;">
                  <input name="end" type="text" id="end" class="form-control layui-input" value="{present name='end'}{$end}{/present}" placeholder=" # 结束时间" autocomplete="off" style="height:34px;width:180px;margin:0 10px;">
                </div>


                <div class="pull-right search">
                  <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px" class="btn btn-default btn-outline" type="submit">搜索</button>
                </div>
                <div class="pull-right search">
                  <input class="form-control input-outline" id="filter" type="text"
                         {php}
                         if(input('?param.name')){
                  if(input('param.name')){
                  echo "value='".input('name')."'";
                  }

                  }
                  {/php}
                  name="name" placeholder="">
                </div>
              </div>
            </form>
          </div>

          <div style="display:block;clear: both;"></div>

          <div class="example">
            <form class="form-horizontal" method="post">
              <table data-toggle="table">
                <thead>
                <tr>
                  <th class="bs-checkbox"><input type="checkbox" id="delidAll"></th>
                  <th>id</th>
                  <th>用户名</th>
                  <th>分类</th>
                  <th>内容</th>
                  <th>地址</th>
                  <th>图片</th>
                  <th>支付方</th>
                  <th>报名费用</th>
                  <th>驳回原因</th>
                  <th>状态</th>
                  <th>活动时间</th>
                  <th>修改时间</th>
                  <th>管理</th>
                </tr>
                </thead>
                <tbody id="form">
                {volist name="data" id="v"}
                <tr id="id{$v.id}" class="class">
                  <td id="delid" ><input name="delAll[]" type="checkbox" value="{$v.id}"></td>
                  <td>{$v.id}</td>
                  <td>
                    <a onclick="member('{$v.user_id}')" style="color:#40BCF7">{$v.user.name}</a>
                  </td>
                  <td id="name">{$v.category}</td>
                  <td id="name">{$v.content}
                    {eq name="v.private" value="1"}
                        <span class="label label-primary">私密</span>
                    {/eq}
                    {eq name="v.sizes" value="0"}
                        <span class="label label-primary">单人</span>
                    {/eq}
                    {neq name="v.limit_uid" value="0"}
                        <span class="label label-primary">仅用户ID（{$v.limit_uid}）可参与</span>
                    {/neq}
                    {if condition="$v.sex == 1"}
                        <span class="label label-primary">仅限男</span>
                    {elseif condition="$v.sex == 2"}
                        <span class="label label-primary">仅限女</span>
                    {/if}
                  </td>
                  <td id="name">
                    <a onclick="address('{$v.address_id}')" style="color:#40BCF7">{$v.address_name}</a>
                  </td>
                  <td>
                    {volist name="v.images" id="image"}
                      <a href="__ROOT__{$image}" target="_blank">
                          <img style="width:40px;height:40px;" src="__ROOT__{$image}"/>
                      </a>
                      {/volist}
                  </td>
                  <td>{$v.pay == 1 ? '报名者' : '发起者'}</td>
                  <td>{$v.price > 0 ? $v.price : ''}</td>
                  <td>{$v.reason}</td>
                  <td id="hide{$v.id}"><?php
                    if($v['status'] == 1){
                      echo "<span class='btn btn-primary btn-xs'>通 过</span>";
                    }elseif($v['status'] == 0){
                      echo "<span class='btn btn-danger btn-xs'>审 核</span>";
                    }else{
                      echo "<span class='btn btn-default btn-xs'>拒 绝</span>";
                    }
                    ?></td>
                  <td>{$v.activity_time}</td>
                  <td><span {php}if(date('Ymd')==date('Ymd',$v['update_time']))echo 'style="color: #ed5565"';{/php}>{$v.update_time|date='Y-m-d H:i:s',###}</span></td>
                  <td>
                    <div class="btn-group">
                      <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span class="caret"></span>
                      </div>
                      <ul class="dropdown-menu">
                                          <li><a onClick="add('{:url('add',['id'=>$v['id'],'url'=>-1])}')">修改</a></li>
                                          <li class="divider"></li>
                        {switch name="$v.status"}
                        {case value="-1"}
                        <li><a onClick="shenhe({$v.id},'0')">审核</a></li>
                        <li><a onClick="shenhe({$v.id},'1')"><span style="color: #1ab394; ">通过</span></a></li>
                        {/case}
                        {case value="0"}
                        <li><a onClick="shenhe({$v.id},'1')"><span style="color: #1ab394; ">通过</span></a></li>
                        <li><a onClick="shenhe({$v.id},'-1')"><span style="color: #ed5565; ">拒绝</span></a></li>
                        {/case}
                        {case value="1"}
                        <li><a onClick="shenhe({$v.id},'-1')"><span style="color: #ed5565; ">拒绝</span></a></li>
                        <li><a onClick="shenhe({$v.id},'0')">审核</a></li>
                        {/case}
                        {/switch}
                        <!-- 
                        <li class="divider"></li>
                        <li>
                          <a onclick="add('{:url('add',['id'=>$v['id'],'url'=>-1])}')">修改</a>
                        </li><li class="divider"></li>
                        <li><a onclick="del({$v.id})">删除</a>
                        </li> -->
                      </ul>
                    </div>
                  </td>
                </tr>
                {/volist}
                </tbody>
              </table>
            </form>
          </div>
        </div>
      </div>
      <hr>
      <div class="row row-lg">
       <div class="col-sm-6">
            <div  class="btn btn-outline btn-default" onclick="alla(1)">
                批量通过
            </div>
            <div  class="btn btn-outline btn-default" onclick="alla(-1)">
                批量拒绝
            </div>
            <div  class="btn btn-outline btn-default" onclick="alla(0)">
                批量审核
            </div>
            <div  class="btn btn-outline btn-default" onclick="alla('del')">
                批量删除
            </div>
        </div> 
        <div class="col-sm-12 pages">{$page}</div>
      </div>
    </div>
  </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
  $(document).ready(function(){
    $('#delidAll').click(function(){
        $('input[type=checkbox]').each(function(){
            var self=$(this);
            if(!self.prop('checked')){
                self.prop('checked',true);
            }else{
                self.prop('checked',false);
            }
        });
    })
    layui.use(['laydate'], function(){
        var laydate = layui.laydate;

        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });
    })
  });
  function del(id){
    swal_del(id,"{:url('del')}")
  }

  function member(id)
  {
      layui.use('layer', function(){
          var layer = layui.layer;
          layer.open({
              title :'预览',
              area: ['100%', '100%'],
              type: 2,
              content: '{:url("member/index")}?search=id&name='+id
          });
      });
  }
  function address(id)
  {
      layui.use('layer', function(){
          var layer = layui.layer;
          layer.open({
              title :'预览',
              area: ['100%', '100%'],
              type: 2,
              content: '{:url("address/claim")}?search=id&name='+id
          });
      });
  }
  function watch(content) {
    layui.use('layer', function(){
      var layer = layui.layer;
      layer.open({
          title :'预览',
          area: ['100%', '100%'],
          type: 1,
          content: content
        });
    });
  }
  function shenhe(id,value){
    if(value == -1){
      layer.prompt({
        formType: 2,
        value: '',
        title: '请输入拒绝原因',
        area: ['500px', '350px'] //自定义文本域宽高
      }, function(reason, index, elem){
        shenheAction(id, value, reason)
        layer.close(index);
      });
    } else {
      shenheAction(id,value)
    }
  }
  function shenheAction(id,value,reason='') {
      ajaxFun("post","{:url('shenhe')}",{id:id,shenhe:value,reason},'json',function(ret){
          if(ret){
              if(ret.ret){
                  layer.msg(ret.ret)
                  window.location.reload()
              }else{
                  layer.msg(ret.err)
              }
          }else{
              swal_msg("错误",ret,"error");
          }
      })
  }
  function alla(types){
      var all=$(".form-horizontal").serialize();
      var alls=$(".form-horizontal").serializeArray();
     console.log(JSON.stringify(alls))

      var index = layer.load(2, {shade: [0.3,'#000']})
      ajaxFun("post",'{:url('shenheAll')}?type='+types,all,'json',function(ret){
          layer.close(index);
          if(ret){
              var text
              switch(types)
              {
              case -1:
                text = '<span class="btn btn-default btn-xs">拒 绝</span>';
                break;
              case 0:
                text = '<span class="btn btn-danger btn-xs">审 核</span>';
                break;
              case 1:
                text = '<span class="btn btn-primary btn-xs">通 过</span>';
                break;
              }
              for(var i=0;i<alls.length;i++){
                  if(types=='del'){
                      $('#id'+alls[i]['value']).remove();
                  }else{
                      $('#hide'+alls[i]['value']).html(text);
                  }
              }
               
              swal_msg('操作成功')
          }
      })
       
  }
</script>
